<template>
  <view class="yd">
    <view class="yd-row-1">
      <view>订单编号: {{item.receiveId}}</view>
      <view
        :class="item.usageState==='1'?'continiu':'finish'"
      >{{item.usageStateDisplay}}</view>
    </view>
    <view class="yd-row-2">
      <image :src="FILE_HOST+item.picturePath" />
      <view class="yd-row-2-right">
        <view>{{item.volumeName}}</view>
        <view>面值:{{item.salesPrice}}</view>
        <view>有效期至:{{item.endTime}}</view>
      </view>
    </view>
    <view class="yd-row-3">
      <view>领取人:{{phoneFormat}}</view>
      <view v-if="item.usageState!=='1'">核销码:{{item.awardCode}}</view>
      <view v-if="item.usageState!=='1'">核销时间:{{item.usageTime}}</view>
    </view>
    <view class="yd-row-4" v-if="item.usageState === '1'">
      <button @tap="handleShuma">输码验证</button>
      <button @tap="handleshaoma">扫码验证</button>
    </view>
  </view>
</template>

<script>
import CONSTS from '@/src/consts';
import {confirm} from '../index/api.js'
export default {
  props: {
    item: {
      type: Object,
      default: () => {
        return {
			
		}
      }
    }
  },
  data () {
    return {
      FILE_HOST: CONSTS.FILE_HOST,
	  keyInputProps:'',
    }
  },
  computed: {
    phoneFormat () {
      var tel = this.item.memberMobile
      tel = "" + tel;
      var tel1 = tel.replace(tel.substring(3, 7), "****")
      return tel1
    }
  },
  methods: {
    handleShuma () {
      // this.$emit('change',{val:1,c:da})
      this.$utils.common.navigateTo('src/pages/index/pages/comput/index')
    },
	handleshaoma(){
		let _this = this
		  uni.scanCode({
		    onlyFromCamera: true,
		    success: function (res) {
		      console.log('条码类型：' + res.scanType);
		      console.log('条码内容：' + res.result);
			  _this.keyInputProps = res.result
			  _this.handleConfirm()
		    }
		  });
	},
	async handleConfirm(){
	  const params={awardCode:parseInt(this.keyInputProps)}
	  try{
	    const {data}=await confirm(params)
	    // this.$toest('兑换成功')
		this.$utils.common.toast.fail("兑换成功");
		setTimeout(() => {
		    uni.redirectTo({
		    	url:'/src/pages/order/index'
		    })
		}, 1000)
	  }catch(err){
	    console.log(err,7878787878)
		this.$utils.common.toast.fail(err.data.message);
	    // this.$toest(err.data.message)
	  }
	},
  },
}
</script>

<style lang="scss" scoped>
.finish {
  color: rgba(149, 151, 166, 1) !important;
}
.continiu {
  color: rgba(245, 49, 29, 1) !important;
}
.yd {
  padding: 30rpx;
  padding-top: 36rpx;
  margin: 0 auto;
  margin-top: 24rpx;
  width: 702rpx;

  background: rgba(255, 255, 255, 1);
  opacity: 1;
  border-radius: 20rpx;
  &-row-1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    view:nth-child(1) {
      font-size: 28rpx;
      font-family: PingFang SC;
      font-weight: 400;
      color: rgba(3, 3, 3, 1);
      opacity: 1;
    }
    view:nth-child(2) {
      font-size: 32rpx;
      font-family: PingFang SC;
      font-weight: 400;
      color: rgba(245, 49, 29, 1);
      opacity: 1;
    }
  }
  &-row-4 {
    padding-top: 42rpx;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    button {
      margin-left: 20rpx;
      font-size: 28rpx;
      font-family: PingFang SC;
      font-weight: 400;
      line-height: 60rpx;
      color: rgba(3, 3, 3, 1);
      opacity: 1;
      width: 200rpx;
      height: 60rpx;
      background: rgba(255, 255, 255, 1);
      border: 1rpx solid rgba(221, 221, 221, 1);
      opacity: 1;
      border-radius: 10rpx;
    }
  }
  &-row-3 {
    padding-top: 40rpx;
  }
  &-row-2 {
    padding-top: 44rpx;
    display: flex;
    image {
      margin-right: 24rpx;
      width: 160rpx;
      height: 160rpx;
      background: rgba(0, 0, 0, 1);
      opacity: 1;
      border-radius: 10rpx;
    }
    &-right {
      view:nth-child(1) {
        font-size: 28rpx;
        font-family: PingFang SC;
        font-weight: 400;
        color: rgba(3, 3, 3, 1);
        opacity: 1;
      }
      view:nth-child(2) {
        padding: 28rpx 0;
        font-size: 24rpx;
        font-family: PingFang SC;
        font-weight: 400;

        color: rgba(149, 151, 166, 1);
        opacity: 1;
      }
      view:nth-child(3) {
        font-size: 24rpx;
        font-family: PingFang SC;
        font-weight: 400;

        color: rgba(149, 151, 166, 1);
        opacity: 1;
      }
    }
  }
}
</style>